package com.secf.service.port.hpy.hys.test.day4;

import java.util.Arrays;

/**
 * @Author ms
 * @Date 2024-08-08
 */

public class CommonArrayIssuesTest {
    public static void main(String[] args) {
        // 测试数组越界
        try {
            int[] numbers = {1, 2, 3};
            int invalidIndex = numbers[3]; // 越界访问
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Caught ArrayIndexOutOfBoundsException: " + e);
        }

        // 测试空指针异常
        try {
            String[] names = new String[3];
            String name = names[0].toUpperCase(); // 未初始化的元素
        } catch (NullPointerException e) {
            System.out.println("Caught NullPointerException: " + e);
        }

        // 测试数组与集合转换
        String[] fruits = {"Apple", "Banana", "Cherry"};
        System.out.println("List from array: " + Arrays.asList(fruits));

        // 测试数组的深拷贝
        int[] original = {1, 2, 3};
        int[] copy = Arrays.copyOf(original, original.length);
        System.out.println("Original array: " + Arrays.toString(original));
        System.out.println("Copied array: " + Arrays.toString(copy));
    }
}

